#ifndef __DEVICE_USART_H__
#define __DEVICE_USART_H__

#include <stdint.h>

typedef enum
{
    Device_COM1 = 0,
    Device_COM2 = 1,
    Device_COM3 = 2,
    Device_COM4 = 3,
    Device_COM5 = 4,
}DeviceCOMType;

typedef struct
{
    uint8_t *Start;         /* point to the start of the queue */
    uint8_t *End;           /* point to the end of the queue */
    uint8_t *In;            /* point to the insert of the queue */
    uint8_t *Out;           /* point to the out of the queue */
    uint16_t Size;          /* total size of the queue */
    uint16_t MessageSize;   /* current number of the message in the queue */
}DataStruct;

typedef struct
{
    DataStruct TxDataStruct;
    DataStruct RxDataStruct;
    void (*Open)(uint32_t baud);
    void (*Start)();
    void (*Stop)();
    uint8_t (*Analyze)(uint8_t *buf,uint16_t buflen);
}DeviceCOMStruct;

void DeviceCOMTxTask(int8_t id);
void DeviceCOMRxTask(int8_t id,uint8_t byte);
void DeviceCOMOpen(int8_t id,uint32_t baud);
void DeviceCOMWriteByte(int8_t id,uint8_t byte);
void DeviceCOMWriteBuffer(int8_t id,uint8_t *buffer,uint16_t len);
void DeviceCOMWriteString(int8_t id, uint8_t *buffer);
void DeviceCOMWriteByteBlock(int8_t id,uint8_t byte);
void DeviceCOMWriteBufferBlock(int8_t id,uint8_t *buffer,uint16_t len);
void DeviceCOMWriteStringBlock(int8_t id, uint8_t *buffer);
uint16_t GetDeviceCOMRxBufLen(int8_t id);
uint16_t GetDeviceCOMRxBuffer(int8_t id,uint16_t rlen,uint8_t *buffer);
void DeviceCOM_StartCallBack(int8_t id);
void DeviceCOM_StopCallBack(int8_t id);
uint8_t DeviceCOMInsertAnalyzeHook(int8_t id,uint8_t(*fun)(uint8_t *buf,uint16_t buflen));
#endif


